package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.community.model.Organization;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.privilege.service.impl.CommonPrivilegeCriteriaEnhancer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/** 
 * 旅居
 * 计划制定
 * @author sunchenlong
 * 
 * 模型评审：新增模型，wulina 2016-09-07
 * 
 * */
@Entity
@Indexed
@Table(name = "travel_plan")
@CriteriaEnhancers(criteriaEnhancers = {@CriteriaEnhancer(impl = OrderCriteriaEnhancer.class),
		@CriteriaEnhancer(impl = CommonPrivilegeCriteriaEnhancer.class, parameter = "organization:organization") })
public class Plan extends BaseModel{

	private static final long serialVersionUID = -8330377479701314560L;

	@Id
	@DocumentId
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long pkPlan;
	
	/** 所属机构*/
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkOrganization")
    @IndexedEmbedded(depth = 1)
	private Organization organization;
	
	/** 年度*/
	@Field
	@Column
	@Between
	private Date year;
	
	/** 计划版本*/
	@Field
	@Column
	private String verNumber;
	
	/** 计划名称*/
	@Field
	@Column
	private String planTitle;

	/** 年度计划介绍*/
	@Field
	@Column
	private String introduction;
	
	/** 其他事项说明*/
	@Field
	@Column
	private String explanation;
	
	/** 编制人*/
	@Field
	@Column
	private String editor;

	/** 编制日期*/
	@Field
	@Column
	private Date editorDate;
	
	/** 发布人*/
	@Field
	@Column
	private String publisher;
	
	/** 发布日期*/
	@Field
	@Column
	private Date publisherDate;

	/** 与子计划.关联表*/
	@ManyToMany
	@JoinTable(name = "travel_plan_planitem",
	joinColumns = {@JoinColumn(name = "pkPlan")},
	inverseJoinColumns = {@JoinColumn(name = "pkPlanItem")})
	@IndexedEmbedded(depth = 1)
	private Set<PlanItem> planItem;
	
	/** 状态*/
	@Enumerated(EnumType.STRING)
	@Field
	@In
	@FieldBridge(impl = EnumBridge.class)
	private Status status;
	
	/** 状态枚举*/
	@JsonSerialize(using = EnumSerializer.class)
	public static enum Status{
		UnRelease("暂存"),
		Disable("停用"),
		Release("发布");
		private String display;
		private Status(String display){
			this.display = display;
		}
		public String getDisplay() {
			return display;
		}
		public void setDisplay(String display) {
			this.display = display;
		}
	}
	
	@Version
	private Integer version;

	public Long getPkPlan() {
		return pkPlan;
	}

	public void setPkPlan(Long pkPlan) {
		this.pkPlan = pkPlan;
	}

	public Organization getOrganization() {
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

	public Date getYear() {
		return year;
	}

	public void setYear(Date year) {
		this.year = year;
	}

	public String getVerNumber() {
		return verNumber;
	}

	public void setVerNumber(String verNumber) {
		this.verNumber = verNumber;
	}

	public String getPlanTitle() {
		return planTitle;
	}

	public void setPlanTitle(String planTitle) {
		this.planTitle = planTitle;
	}

	public String getIntroduction() {
		return introduction;
	}

	public void setIntroduction(String introduction) {
		this.introduction = introduction;
	}

	public String getExplanation() {
		return explanation;
	}

	public void setExplanation(String explanation) {
		this.explanation = explanation;
	}

	public String getEditor() {
		return editor;
	}

	public void setEditor(String editor) {
		this.editor = editor;
	}

	public Date getEditorDate() {
		return editorDate;
	}

	public void setEditorDate(Date editorDate) {
		this.editorDate = editorDate;
	}

	public String getPublisher() {
		return publisher;
	}

	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}

	public Date getPublisherDate() {
		return publisherDate;
	}

	public void setPublisherDate(Date publisherDate) {
		this.publisherDate = publisherDate;
	}

	public Set<PlanItem> getPlanItem() {
		return planItem;
	}

	public void setPlanItem(Set<PlanItem> planItem) {
		this.planItem = planItem;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	
}
